package com.dongdongshop.service;

import com.dongdongshop.data.Page;
import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.pojo.TbGoodsDesc;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.pojo.TbSellerExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@DubboService
public class TbSellerServiceImpl implements TbSellerService {

    @Autowired
    private TbSellerMapper tbSellerMapper;

    @Override
    public Page selectAll(TbSeller tbSeller, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbSeller> tbSellers =tbSellerMapper.selectBy(tbSeller);
        PageInfo info = new PageInfo(tbSellers);
        return new Page(info.getPageNum(),info.getPageSize(),info.getPages(),info.getTotal(),info.getList());

    }

    @Override
    public TbSeller selectDetails(TbSeller tbSeller) {
        //根据SellerId查询数据
        TbSellerExample tse = new TbSellerExample();
        TbSellerExample.Criteria criteria = tse.createCriteria();
        criteria.andSellerIdEqualTo(tbSeller.getSellerId());
        List<TbSeller> tbSellers = tbSellerMapper.selectByExample(tse);
        TbSeller tbSeller1 = tbSellers.size() > 0 ? tbSellers.get(0) : null;
        return tbSeller1;
    }

    @Override
    public boolean updateBy(TbSeller tbSeller) {
        int i = tbSellerMapper.updateByTb(tbSeller);
        return i>0;
    }

    @Override
    public boolean updateBying(TbSeller tbSeller) {
        int i = tbSellerMapper.updateByIng(tbSeller);
        return i>0;
    }

    @Override
    public boolean updateByNo(TbSeller tbSeller) {
        int i = tbSellerMapper.updateByNo(tbSeller);
        return i>0;
    }


}
